package hongsong.eqixueweb.common;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream; 
import java.util.Iterator;
import java.util.Properties;

import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;

public class ReadFile {
	
	public String readpro(String conkey){
		         Properties prop = new Properties();     
		        try{
		             //��ȡ�����ļ�a.properties
		           InputStream in = new BufferedInputStream (new FileInputStream(this.getClass().getResource("/config/config.properties").getPath()));
		           prop.load(in);     ///���������б�
		           Iterator<String> it=prop.stringPropertyNames().iterator();
		            while(it.hasNext()){
		                String key=it.next();
		                if(key.equals(conkey)){
		                	return prop.getProperty(key);
		                }
//		                System.out.println(key+":"+prop.getProperty(key));
		                
		            }
		            in.close();
		            
		         }
		         catch(Exception e){
		             System.out.println(e);
		         }
		        return null;
	}
	
	/**
	* 上传文件，需要点击弹出上传照片的窗口才行
	*
	* @parambrower
	*            使用的浏览器名称
	* @paramfile
	*            需要上传的文件及文件名*/
	 public void fileUpload(String browser, File file) {
		    String filePath= file.getAbsolutePath();
//		    String executeFile= "res/script/autoit/Upload.exe"; //定义了upload.exe文件的路径
		    String executeFile= this.getClass().getResource("/driver/upfile-x86.exe").getPath();
		    String newfilepath = executeFile.substring(1);
		    System.out.println(newfilepath);
		    String cmd= "\""+ newfilepath+ "\""+ " "+ "\""+ browser+ "\""+ " "+ "\""+ filePath+ "\"";
		    try{
		        Process p= Runtime.getRuntime().exec(cmd);
		        p.waitFor();
		    } catch(Exception e) {
		        e.printStackTrace();
		    }
	} 
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		ReadFile rf = new ReadFile();
		String test=rf.readpro(Keywords.key_url);
		System.out.println(test);
	}

}
